Formius.Element_Value = $.inherit({
	/**
	 * @var Formius.Element_Abstract
	 */
	_element: null,
	/**
	* @var String
	*/
	_code: null,

	/**
	* @var Object
	*/
	_messages: {
		UNKNOWN_COMPARE: 'Не передано значение для сравнения',
		UNKNOWN_FIELD: 'У формы нет поля с именем «{field}»'
	},
	/**
	* @var Object
	*/
	_options: {},

	__constructor: function(options, form) {
		this.setOptions(options);
		if (!('element' in this.getOptions())) {
			this._setCode('UNKNOWN_COMPARE');
			return;
		}
		this._setElement(form.getElementByName(this.getOptions().element));
		if (!this.getElement()) {
			this._setCode('UNKNOWN_FIELD');
			return;
		}
	},
	_setElement: function(element) {
		this._element = element;
		return this;
	},
	getElement: function() {
		return this._element;
	},
	/**
	 * @return Mixed
	 */
	getValue: function() {
		return (this.getCode() == null? this._element.getValue(): null);
	},
	/**
	* @return String
	*/
	getCode: function() {
		return this._code;
	},
	/**
	* @return String
	*/
	getMessage: function() {
		if (this.getCode() == null) {
			return null;
		}
		if (typeof(this._messages[this.getCode()] != 'undefined')) {
			var message = this._messages[this.getCode()];
			for (var i in this._options) {
				message = Formius.Helper.replace('{' + i + '}', this._options[i], message);
			}
			return message;
		}
		return this.getCode();
	},
	/**
	* @param Object messages
	* @return Void
	*/
	setMessages: function(messages) {
		this._messages = $.extend(this._messages, messages);
		return this;
	},

	/**
	* @param Object options
	*/
	setOptions: function(options) {
		this._options = $.extend(this._options, options || {});
		return this;
	},
	getOptions: function() {
		return this._options;
	},
	/**
	* @param String code
	*/
	_setCode: function(code) {
		this._code = code;
		return this;
	},
	toString: function() {
		return '' + this.getValue();
	}
});